package com.example.demo1.generator.codedesign.model;

import java.util.Objects;

/**
 * 表单类型
 * 
 * @author lake
 *
 */
public enum FormType {

	INPUT("INPUT"), 
	INPUT_NUMBER("INPUT_NUMBER"), 
	CHECKBOX("CHECKBOX"), 
	COMBOX("COMBOX"), 
	DATE("DATE"), 
	TIME("TIME"), 
	DATETIME("DATETIME"), 
	TEXTAREA("TEXTAREA");

	private String code;

	private FormType(String c) {
		this.code = c;
	}

	public String getCode() {
		return this.code;
	}

	public static FormType getInstance(String code) {
		FormType instance = null;
		for (FormType item : values()) {
			if (Objects.equals(item.getCode(), code)) {
				instance = item;
			}
		}
		return instance;
	}

	public static FormType transform(PropertyType propertyType) {
		FormType instance = FormType.INPUT;
		if (PropertyType.BOOLEAN == propertyType) {
			instance = FormType.COMBOX;
		} else if (PropertyType.DATE == propertyType) {
			instance = FormType.DATE;
		} else if (PropertyType.DATETIME == propertyType) {
			instance = FormType.DATETIME;
		} else if (PropertyType.INTEGER == propertyType || PropertyType.LONG == propertyType
				|| PropertyType.DECIMAL == propertyType) {
			instance = FormType.INPUT_NUMBER;
		}
		return instance;
	}

}
